package com.example.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * Description:
 * User: 阿宾
 * Date: 2025-05-04
 * Time: 18:38
 */
public class JDKInvocationHandler implements InvocationHandler {
    private Object target;//目标对象

    public JDKInvocationHandler(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("我是中介，开始代理");
        //通过反射，调用目标对象的方法
        Object result = method.invoke(target, args);
        System.out.println("我是中介，结束代理");
        return result;
    }
}
